<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="layuiadmin/style/admin.css" media="all">
    <link rel="stylesheet" href="layuiadmin/style/admin1.css" media="all">
    <link rel="stylesheet" href="layuiadmin/modules/loadsearch/load.css" media="all">
    <link rel="stylesheet" href="src/all.css" media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        #formAdvForm .layui-form-item {
      margin-top: 20px;
      margin-bottom: 0;
    }

    #formAdvForm .layui-form-item .layui-inline {
      margin-bottom: 25px;
      margin-right: 0;
    }

    .form-group-bottom {
      position: fixed;
      left: 0;
      right: 0;
      bottom: 0;
      padding: 10px 20px;
      background-color: #fff;
      box-shadow: 0 -1px 2px 0 rgba(0, 0, 0, .05);
    }

    .layui-form-label {
      white-space: nowrap;
    }

    /* //css调整部分 */
    xm-select{
        border-color: #1890ff !important;
    }
    xm-select .scroll-body {
      padding-left: 10px;
      overflow: hidden;
    }
    xm-select .xm-body{
        width: 100%;
    }
    @media screen and (max-width: 1280px) {
          #peerpeople  xm-select .xm-body{
            left :-200px
        }  
    }


    .file-choose-list-item-img.img-icon {
      /*background-size: cover;*/
    }

    #a {
        height: 450px;
    }
    #b {
        height: 450px;
    }
    #c {
        height: 450px;
    }
    .load_textnext {
      width: 100%;
      height: 200px;
      background-color: #fff;
      border: 1px solid #eee;
      border: 1px solid #d2d2d2;
      box-shadow: 0 2px 4px rgb(0 0 0 / 12%);
      background-color: #fff;
      color: #666;
      position: absolute;
      z-index: 2;
      overflow: auto;
    }

    .load_textnext div {
      padding: 5px;
    }

    .load_textnext div:hover {
      background-color: #FAFAFA;
    }

    .textnext {
      width: 100%;
      height: 200px;
      background-color: #fff;
      border: 1px solid #eee;
      border: 1px solid #d2d2d2;
      box-shadow: 0 2px 4px rgb(0 0 0 / 12%);
      background-color: #fff;
      color: #666;
      position: absolute;
      z-index: 2;
      overflow: auto;

    }

    .textnext div {
      padding: 5px;
    }

    .textnext div:hover {
      background-color: #FAFAFA;
    }

    .cl-select {
      margin-bottom: 0 !important;
    }

    .cl {
      margin: 10px 0;
      margin-bottom: 10px !important;
    }

    .hide {
      display: none;
    }
    .layui-textareas{
      min-height: auto;
     border-color: #1890ff;
    }
    .layui-input, .layui-textareas {
           border-color: #1890ff;
    }
    .layui-input:hover, .layui-textareas:hover {
        border-color: #000!important;
    }
    .layui-btn-mldblur{
        background-color: #0064c8;
        border-color: #0064c8;
    }
    .layui-form-item .layui-inline {
    margin-bottom: 25px;
     margin-right: 0px !important; 
}
  </style>
</head>

<body>
    <!-- 正文开始 -->
    <div class="layui-form" id="formAdvForm" lay-filter="formAdvForm">
        <div class="layui-fluid" style="padding-bottom: 75px;margin-top: 10px;">
            <div class="layui-form" id="formAdvForm_basis" lay-filter="formAdvForm_basis" style="margin-bottom: 15px;">
                <div class="layui-card">
                    <!-- hidden -->
                    <input type="hidden" value="$!isadd" name="isadd" />
                    <!-- 录入人 -->
                    <input type="hidden" value="$cls.setck('names')" name="yh_enroll" />
                    <!-- 录入人所在部门 -->
                    <input type="hidden" value="$cls.setck('department_id')" name="yh_enroll_id" />
                    <div class="layui-card-header">基础信息</div>
                    <div class="layui-card-body">
                        <div class="layui-form-item layui-row">
                            <div class="layui-inline layui-col-md12 layui-col-sm12">
                                <label class="layui-form-label layui-form-required">责任部门:</label>
                                <!--责任部门  -->
                                <div class="layui-input-block">
                                    <input type="text" readonly autocomplete="off" lay-verify="required" lay-reqText='请选择责任部门！' lay-verType='msg' class="layui-input" id='depart' value="" name='bumen_name'>
                                </div>
                                <!-- 部门id -->
                                <input type="hidden" id='depart_id' value="" name='responsibledepartme'>
                                <!-- 保存一个主体部门 -->
                                <input type="hidden" id='pname' value="" name='depart_pname'>
                            </div>
                            <div class="layui-inline layui-col-md6 layui-col-sm6">
                                <label class="layui-form-label layui-form-required">检查地点:</label>
                                <div class="layui-input-block">
                                    <!-- 检查地点 -->
                                    <input type="hidden" id='address_id' name='address' lay-reqText='请选择地点！' lay-verType='msg' value="" lay-verify="required" placeholder="请输入" accept="off" class="layui-input">
                                    <input type="text" id='address_name' name='address_name' lay-verType="tips" lay-verify="required" autocomplete="off" placeholder="请输入" accept="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md6 layui-col-sm6">
                                <label class="layui-form-label ">详细地点:</label>
                                <div class="layui-input-block">
                                    <!-- 详细地点 -->
                                    <input name="yh_address_all" value="$!yh_address_all" placeholder="请输入" class="layui-input" />
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md4 layui-col-sm4">
                                <label class="layui-form-label layui-form-required">检查人:</label>
                                <div class="layui-input-block">
                                    <!-- 检查人 -->
                                    <div id="inspeople"></div>
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md4 layui-col-sm4">
                                <label class="layui-form-label ">陪检人:</label>
                                <div class="layui-input-block">
                                    <!-- 陪检人 -->
                                    <div id="accompany"></div>
                                </div>
                            </div>
                            <!--  -->
                            <div class="layui-inline layui-col-md4 layui-col-sm4">
                                <label class="layui-form-label ">同行人:</label>
                                <div class="layui-input-block">
                                    <!-- 陪检人 -->
                                    <div id="peerpeople"></div>
                                </div>
                            </div>
                            <!--  -->
                            <div class="layui-inline layui-col-md4 layui-col-sm4">
                                <label class="layui-form-label layui-form-required">检查日期:</label>
                                <div class="layui-input-block">
                                    <!-- 检查日期 -->
                                    <input id="formAdvDateSel1" name="inspectiondate" value="$!inspectiondate" placeholder="请选择开始和结束日期" class="layui-input icon-date" autocomplete="off" lay-verType="tips" lay-verify="required" />
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md7 layui-col-sm8">
                                <label class="layui-form-label">班次:</label>
                                <!-- #set($oldclass="SELECT xt_dict_id AS ids, to_char( xt_dict_createdate, 'yyyy-mm-dd') AS createdate, xt_dict_json ->> 'dict_code' AS dict_code, xt_dict_json ->> 'dict_pid' AS dict_pid, xt_dict_json ->> 'sort' AS sort, xt_dict_json ->> 'dict_text' AS dict_text, xt_dict_json ->> 'dict_name' AS dict_name, xt_dict_json ->> 'type' AS TYPE, xt_dict_json ->> 'color' AS color, xt_dict_json ->> 'isshow' AS isshow FROM xt_dict WHERE xt_dict_json ->> 'type' = 'oldofclass' ORDER BY sort") -->
                                <!-- #set($oldarr=$cls.getpgdt($oldclass)) -->
                                <div class="layui-input-block" id='oldofclass'>
                                    <!-- #foreach( $item in $oldarr.Rows ) -->
                                    <!-- #if($item.sort ==  1) -->
                                    <input type="radio" checked name="oldofclass" value="$!{item.dict_name}" title="$!{item.dict_name}">
                                    <!-- #else -->
                                    <input type="radio" name="oldofclass" value="$!{item.dict_name}" title="$!{item.dict_name}">
                                    <!-- #end -->
                                    <!-- #end -->
                                </div>
                            </div>
                        </div>
                        <div class="layui-row">
                            <div class="layui-inline layui-col-md7 layui-col-sm8">
                                <label class="layui-form-label">检查类别:</label>
                                <!-- 所在部门 及顶级部门设置 -->
                                <div class="layui-input-block">
                                    <!-- #set($list=$cls.getpgdt("SELECT yh_inspection_id AS ids, to_char(yh_inspection_createdate, 'yyyy-mm-dd hh24:mi:ss') AS createdate , yh_inspection_json ->> 'jiancha_name' AS jiancha_name, yh_inspection_json ->> 'star_time' AS star_time , yh_inspection_json ->> 'end_time' AS end_time, yh_inspection_json ->> 'link_depart' AS link_depart , yh_inspection_json ->> 'link_departname' AS link_departname FROM yh_inspection left JOIN xt_bumen on ( '$cls.setck('department_id')' = xt_bumen_id) WHERE   ( yh_inspection_json ->> 'link_depart' = '$cls.setck('department_id')' or yh_inspection_json ->> 'link_depart' = xt_bumen.xt_bumen_json->>'pname_id')  and LOCALTIMESTAMP(1) >= (yh_inspection_json ->> 'star_time')::TIMESTAMP AND LOCALTIMESTAMP(1) <= (yh_inspection_json ->> 'end_time')::TIMESTAMP ORDER BY yh_inspection_json ->> 'jancha_sort' ASC")) -->
                                    <!-- #if( $cls.setck('department_id') != '000000000000000000000000000000000001')    -->
                                    <!-- #set($listjt=$cls.getpgdt("SELECT yh_inspection_id AS ids, to_char(yh_inspection_createdate, 'yyyy-mm-dd hh24:mi:ss') AS createdate , yh_inspection_json ->> 'jiancha_name' AS jiancha_name, yh_inspection_json ->> 'star_time' AS star_time , yh_inspection_json ->> 'end_time' AS end_time, yh_inspection_json ->> 'link_depart' AS link_depart , yh_inspection_json ->> 'link_departname' AS link_departname FROM yh_inspection left JOIN xt_bumen on ( '000000000000000000000000000000000001' = xt_bumen_id) WHERE   ( yh_inspection_json ->> 'link_depart' = '000000000000000000000000000000000001' or yh_inspection_json ->> 'link_depart' = xt_bumen.xt_bumen_json->>'pname_id')  and LOCALTIMESTAMP(1) >= (yh_inspection_json ->> 'star_time')::TIMESTAMP AND LOCALTIMESTAMP(1) <= (yh_inspection_json ->> 'end_time')::TIMESTAMP ORDER BY yh_inspection_json ->> 'jancha_sort' ASC")) -->
                                    <!-- #end -->
                                    <select name="yh_zhuanxiang" lay-filter="aihao">
                                        <!-- #if($cls.setck('department_id') != '000000000000000000000000000000000001')   -->
                                        <!-- #foreach($rows1 in $listjt.Rows) -->
                                        <option value="$!{rows.ids}">$!{rows1.jiancha_name}</option>
                                        <!-- #end -->
                                        <!-- #end -->
                                        <!-- #foreach($rows in $list.Rows) -->
                                        <option value="$!{rows.ids}">$!{rows.jiancha_name}</option>
                                        <!-- #end -->
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-card">
                <div class="layui-card-header">详细信息</div>
                <div class="layui-card-body">
                    <!-- 此处由单位级别控制 -->
                    <div class="layui-form" id="formAdvForm_leader" lay-filter="formAdvForm_leader">
                        <!--  #if("$cls.setck('level')" != "C" && "$cls.setck('level')" != "E") -->
                        <div class="layui-row">
                            <div class="layui-inline layui-col-md2 layui-col-sm4">
                                <label class="layui-form-label">带班领导:</label>
                                <div class="layui-input-block">
                                    <input type="checkbox" name="leader" lay-skin="switch" lay-text="ON|OFF" title="">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md10 layui-col-sm8">
                                <label class="layui-form-label">行走线路:</label>
                                <div class="layui-input-block">
                                    <input type="text" autocomplete="off" id='yh_route' name="yh_route" value="" class="layui-input">
                                </div>
                            </div>
                        </div>
                        <!-- #end -->
                    </div>
                    <!--  #if(!$!id) -->
                    <div class="layui-row layui-form-item">
                        <div class="layui-col-md12  layui-col-sm12">
                            <label for="" class="layui-form-label">
                                <button id="add_yh_content" class="layui-btn  layui-btn-sm   layui-btn-mldblur">手动添加</button>
                            </label>
                        </div>
                    </div>
                    <!-- #end -->
                    <div id='yhContent'>
                        <form class="layui-form layui-active-row" id="formAdvForm_0" lay-filter="formAdvForm_0">
                            <div class="layui-form-item layui-row">
                                <div class="layui-inline layui-col-md11 layui-col-sm11 layui-col-xs1">
                                    <fieldset class="layui-elem-field">
                                        <legend>隐患内容</legend>
                                        <div class="layui-field-box layui-clear">
                                            <div class="layui-inline layui-col-md8 layui-col-sm12">
                                                <label for="" class="layui-form-label">隐患内容:</label>
                                                <div class="layui-input-block" style="position: relative;">
                                                    <textareas placeholder="请输入内容" rows="2" id="yh_content" lay-verify="required" name="yh_content" class="yh_content layui-textareas"></textareas>
                                                    <div class="textnext hide"></div>
                                                </div>
                                            </div>
                                            <!--  -->
                                            <div class="layui-inline layui-col-md4 layui-col-sm12">
                                                <label for="" class="layui-form-label">整改要求:</label>
                                                <div class="layui-input-block">
                                                    <textareas rows="2" placeholder="请输入内容" name="yh_rectify" class="layui-textareas"></textareas>
                                                </div>
                                            </div>
                                            <!--  -->
                                            <div class="layui-inline layui-col-md12 layui-col-sm12">
                                                <label class="layui-form-label layui-form-required">隐患等级:</label>
                                                <!-- 隐患等级 -->
                                                <!-- #set($oldclass="SELECT xt_dict_id AS ids, to_char( xt_dict_createdate, 'yyyy-mm-dd') AS createdate, xt_dict_json ->> 'dict_code' AS dict_code, xt_dict_json ->> 'dict_pid' AS dict_pid, xt_dict_json ->> 'sort' AS sort, xt_dict_json ->> 'dict_text' AS dict_text, xt_dict_json ->> 'dict_name' AS dict_name, xt_dict_json ->> 'type' AS TYPE, xt_dict_json ->> 'color' AS color, xt_dict_json ->> 'isshow' AS isshow FROM xt_dict WHERE xt_dict_json ->> 'type' = 'yh_grade' ORDER BY sort") -->
                                                <!-- #set($oldarr=$cls.getpgdt($oldclass)) -->
                                                <div class="layui-input-block" id='yh_level'>
                                                    <!-- #foreach( $item in $oldarr.Rows ) -->
                                                    <!-- #if($item.sort ==  1) -->
                                                    <input type="radio" checked name_data="yh_level" name="yh_level" lay-filter="encrypt" value="$!{item.dict_name}~${item.dict_text}~${item.color}" title="$!{item.dict_name}">
                                                    <!-- #else -->
                                                    <input type="radio" name_data="yh_level" name="yh_level" lay-filter="encrypt" value="$!{item.dict_name}~${item.dict_text}~${item.color}" title="$!{item.dict_name}">
                                                    <!-- #end -->
                                                    <!-- #end -->
                                                </div>
                                            </div>
                                            <div class="layui-inline layui-col-md12 layui-col-sm12">
                                                <label for="" class="layui-form-label">要求完成时间</label>
                                                <div class="layui-input-block">
                                                    <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="0" lay-skin="primary" title="当班整改" checked>
                                                    <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="0" lay-skin="primary" title="当天整改">
                                                    <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="1" lay-skin="primary" title="一天整改">
                                                    <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="2" lay-skin="primary" title="二天整改">
                                                    <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="3" lay-skin="primary" title="三天整改">
                                                    <div class="layui-hide">
                                                        <input type="radio" lay-filter="radio" name_data="like" name="like_0" value="4" lay-skin="primary" title="其他整改">
                                                    </div>
                                                    <div class="layui-input-inline">
                                                        <!-- <input form="formAdvForm" type="hidden" value="yh_requesttime" name='add'> -->
                                                        <input type="text" name="yh_requesttime" label_radio="0" value="$!yh_requesttime" id="date_time" class="layui-input">
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </fieldset>
                                </div>
                                <div class="layui-inline layui-col-md1 layui-col-sm1 layui-col-xs1 config_btn layui-hide">
                                    <div class="layui-inline" style="margin-top:5px;">
                                        <a class="layui-link copy-row" href="javascript:;">复制</a>
                                        <a class="layui-link del-row" style="color: red; " href="javascript:;">删除</a>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>
                    <div class="layui-form-item layui-row">
                        <div class="layui-form" id="formAdvForm_del" lay-filter="formAdvForm_del">
                            <div id='del_dept' class="layui-inline layui-col-md5 layui-col-sm4">
                                <label class="layui-form-label layui-form-required">销号部门:</label>
                                <!-- 指定销号部门 -->
                                <div class="layui-input-block">
                                    <input type="text" autocomplete="off" id='del_dm' readonly="" class="layui-input" name='del_dept' lay-verType="tips" lay-verify="required" value="">
                                    <input type="hidden" autocomplete="off" id='del_dm_id' class="layui-input" name='del_dept_id' value="">
                                </div>
                            </div>
                            <div class="layui-inline layui-col-md2 layui-col-sm4">
                                <button type="button" class="layui-btn layui-btn-normal" id="my_dept">本部门</button>
                                <button type="button" class="layui-btn layui-btn-normal" id="res_dept">责任部门</button>
                            </div>
                            <div class="layui-inline layui-col-md5 layui-col-sm4">
                                <label class=" layui-form-label layui-form-required">隐患种类:</label>
                                <div class="layui-input-block">
                                    <!-- 隐患种类  -->
                                    <!-- <input type="hidden" value="yh_kind" name='add'> -->
                                    <div id="yh_kind"></div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <!-- </div> -->
                </div>
            </div>
            <div class="layui-collapse" lay-accordion style="background: #fff;">
                <div class="layui-form" id="formAdvForm_sup" lay-filter="formAdvForm_sup">
                    <div class="layui-colla-item">
                        <h2 class="layui-colla-title">补充信息</h2>
                        <div class="layui-colla-content ">
                            <div class="">
                                <div class="layui-form-item layui-row">
                                    <div class="layui-inline layui-col-md3 layui-col-sm3">
                                        <label class=" layui-form-label  ">责任追究:</label>
                                        <div class="layui-input-block">
                                            <input type="checkbox" name="accountability" lay-skin="switch" value="1" lay-text="是|否">
                                        </div>
                                    </div>
                                    <div class="layui-inline layui-col-md3 layui-col-sm3">
                                        <!-- <input type="hidden" value="yh_fine" name='add'> -->
                                        <label class="layui-form-label">资金:</label>
                                        <div class="layui-input-block">
                                            <input id='zj' type="number" lay-verify="required|number" class='layui-input' value="0" name='yh_fine'>
                                        </div>
                                    </div>
                                </div>
                                <div class="layui-form-item layui-row">
                                    <div class="layui-inline layui-col-md8 layui-col-sm12">
                                        <fieldset class="layui-elem-field">
                                            <legend>上传文件</legend>
                                            <div class="layui-field-box">
                                                <div class="layui-upload">
                                                    <button type="button" class="layui-btn layui-btn-normal" id="testList">选择多文件</button>
                                                    <div class="layui-upload-list">
                                                        <table class="layui-table">
                                                            <colgroup>
                                                                <col>
                                                                <col width="150">
                                                                <col width="260">
                                                                <col width="150">
                                                            </colgroup>
                                                            <thead>
                                                                <tr>
                                                                    <th>文件名</th>
                                                                    <th>大小</th>
                                                                    <th>状态</th>
                                                                    <th>操作</th>
                                                                </tr>
                                                            </thead>
                                                            <tbody id="demoList"></tbody>
                                                        </table>
                                                    </div>
                                                </div>
                                            </div>
                                        </fieldset>
                                    </div>
                                    <div class="layui-inline layui-col-md4 layui-col-sm12">
                                        <fieldset class="layui-elem-field">
                                            <legend>已传文件</legend>
                                            <div class="layui-field-box">
                                                <div id="file-list-group"></div>
                                            </div>
                                        </fieldset>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group-bottom text-right">
            <!-- #if(!$!id) -->
            <button class="layui-btn submit" lay-filter="formAdvSubmit" lay-submit>提交并下达</button>
            <button class="layui-btn submit layui-btn-normal" lay-filter="formAdvSubmitSave" lay-submit>保存</button>
            <!-- #end -->
            <!-- #if($!id ) -->
            <!-- #if($TY != '详情') -->
            <button class="layui-btn submit layui-btn-normal" lay-filter="detailFormAdvSubmitSave" lay-submit>保存</button>
            <!-- #end -->
            <!-- #end -->
            <button class="layui-btn submit layui-top-info" lay-filter="formAdvClose" lay-submit onclick="parent.layer.closeAll()">关闭</button>
        </div>
        <!-- form -->
    </div>
    <div class="mask">
        <i class="load layui-anim-loop layui-anim-rotate layui-anim layui-icon-loading layui-icon"></i>
    </div>
    <script type="text/html" id="toolbarDemo">
        <div class="layui-btn-container cl">

        <div class="layui-inline cl-select">
            <input type="text" name='keyword' style='width:200px;' class="layui-input" placeholder="请输入关键字">
        </div>
        <button type="button" class="layui-btn layui-btn-normal  layui-btn-sm  " lay-event="search">  <i class="layui-icon layui-icon-search" ></i>  </button>
        <button type="button" class="layui-btn layui-btn-primary layui-btn-sm" lay-event="refresh" >
        <i class="layui-icon layui-icon-refresh" ></i> 
        </button>
      </div>
      
    </script>
    <!-- 时间格式化插件 -->
    <script src="layuiAdmin/plug/moment.min.js"></script>
    <script src="layuiadmin/modules/axios.min.js"></script>
    <script src="layuiadmin/modules/qs.js"></script>
    <script src="layuiadmin/layui/layui.js"></script>
    <script>
    layui.config({
        base: 'layuiadmin/modules/'
    }).extend({
        xmSelect: 'xm-select'
    }).use(['form', 'loading', 'loadLine', 'loadsearch', 'notice', 'laydate', 'main', 'table', 'xmSelect', 'treeTable', 'util', 'fileChoose'], function() {
        var form = layui.form,
            table = layui.table,
            $ = layui.jquery,
            layer = layui.layer,
            axios = layui.main,
            notice = layui.notice,
            xmSelect = layui.xmSelect,
            treeTable = layui.treeTable,
            util = layui.util,
            upload = layui.upload,
            element = layui.element,
            transfer = layui.transfer,
            fileChoose = layui.fileChoose,
            laydate = layui.laydate,
            loading = layui.loading,
            loadsearch = layui.loadsearch,
            loadLine = layui.loadLine;

        const RES_LAYDATE = [];
        // new 
        const main = new Main();

        // 初始化
        main.init();


        // 参数
        function Main() {
            // 回显数据
            this.select = ` #set($val = $cls.getpgval("SELECT row_to_json(ts) FROM ( SELECT  * ,to_char(inspectiondate,'yyyy-mm-dd hh24:mi:ss') AS inspectiondate FROM YH WHERE yh_id = '$id' ) ts"))`

            this.user = {
                id: "$cls.setck('ids')",
                name: "$cls.setck('users_name')",
                department_id: "$cls.setck('department_id')",
                department_name: "$cls.setck('department_name')",
                function_perms: "$cls.setck('function_perms')"
            };
            this.defaultform = ['formAdvForm_basis', 'formAdvForm_leader', 'formAdvForm_del', 'formAdvForm_sup']

            this.form = ['formAdvForm_0']

            this.isadd = '$isadd';
            // 录入人
            this.yh_enroll = "$cls.setck('names')";
            this.yh_enroll_id = "$cls.setck('department_id')"; // 录入所在部门

            this.init = function() {
                $('.mask:eq(0)').hide();

                // Click_Element 继承 Main ,Select_Opener 
                inherits(Click_Element, Select_Opener);
                inherits(Click_Element, Main)

                const click_ele = new Click_Element();
                // 选择部门
                click_ele.init();
                // 选择人员
                const select_peopele = new Select_People()
                select_peopele.init()

                // 事件
                const time = new Select_Date();
                time.init();

                // 隐患种类
                const type = new Select_Xmyh_Type();
                type.init();

                // 文件上传
                const upload = new Upload();
                upload.init();

                /* 隐患内容 */
                inherits(Yh_Element, Main)

                const yh = new Yh_Element();
                yh.init();

                /* 保存 */
                inherits(Submit, Main)

                const submit = new Submit();
                submit.init();
            };
            this._set = function(key, value) {
                this[key] = value
            }
        }

        /* 继承关系实现 */
        function inherits(Child, Parent) {
            var F = function() {};
            F.prototype = Parent.prototype;
            Child.prototype = new F();
            Child.prototype.constructor = Child;
        }

        /* 单选 弹窗 */
        function Select_Opener(Parent) {
            // 选择组织机构  单选
            this.url = '${cls.getrooturl()}?type=ajaxshow&tabid=${tabid}&zr=1&mid=${mid}&job=${job}&tbname=${tbname}&T=选择组织机构&input_name=' + $('#depart').val() + '&input=' + $('#depart_id').val();
            this.open = function() {
                let _this = this;
                layer.open({
                    type: 2,
                    zIndex: layer.zIndex, //重点1
                    title: '选择所属部门',
                    shadeClose: true,
                    shade: true,
                    maxmin: false, //开启最大化最小化按钮
                    area: ['60%', '90%'],
                    btn: ['确定', '取消'],
                    content: _this.url,
                    success: function(layero, index) {
                        _this.success(layero, index)
                    },
                    yes: function(index) { _this.yes(index) }
                })
            };
            this.success = function(layero, index) {
                let _this = this
                var iframeWindow = window['layui-layer-iframe' + index]
                iframeWindow.addEventListener('dblclick', () => {
                    var el = iframeWindow.layui.el;
                    if (el) {
                        let data = el.getRadioChecked()
                        if (data.length == 1) {

                            _this.ele_id.val(data[0].id)
                            _this.ele.val(data[0].bumen_name)
                            if (_this.min_dept_id) {
                                // 主体部门
                                _this.min_dept_id.val(data[0].pname_id);
                            }

                            layer.close(index)
                        }
                    }
                })
            };
            this.yes = function(index) {
                let _this = this

                var iframeWindow = window['layui-layer-iframe' + index]
                let data = iframeWindow.layui.el.getRadioChecked()
                if (data.length <= 0) {
                    layer.msg('请选择数据')
                    return;
                }
                _this.ele_id.val(data[0].id)
                _this.ele.val(data[0].bumen_name);
                if (_this.min_dept_id) {
                    _this.min_dept_id.val(data[0].pname_id);
                }

                layer.close(index)
            }

        }

        /* 点击元素 事件 */
        function Click_Element() {
            // 给弹窗类使用
            this.ele = null;
            this.ele_id = null;
            this.min_dept_id = null;
            // 继承部门弹窗 
            Select_Opener.call(this);
            Main.call(this);

            this.init = function() {
                this.duty();
                this.sales();
                this.mybtn();
                this.dutybtn();
            }
            // 责任部门
            this.duty = function() {
                let _this = this;
                _this.ele = $('#depart');

                this.ele.on('click', function() {
                    _this.ele = $('#depart');
                    _this.ele_id = $('#depart_id');
                    _this.min_dept_id = $('#pname');
                    _this.open()
                })
            };
            // 销号部门 选择
            this.sales = function() {
                let _this = this;
                _this.ele = $('#del_dm')

                this.ele.on('click', function() {
                    _this.ele = $('#del_dm')
                    _this.ele_id = $('#del_dm_id')
                    _this.min_dept_id = null;
                    _this.open()
                })


            }
            // 本部门
            this.mybtn = function() {
                let _this = this;
                _this.ele = $('#my_dept')

                this.ele.on('click', function() {
                    _this.ele = $('#del_dm')
                    _this.ele_id = $('#del_dm_id')

                    let name = _this.user.department_name;
                    let id = _this.user.department_id;

                    _this.ele.val(name)
                    _this.ele_id.val(id)
                    // _this.open()
                })
            }
            // 本部门
            this.dutybtn = function() {
                let _this = this;
                _this.ele = $('#res_dept')

                this.ele.on('click', function() {
                    _this.ele = $('#del_dm')
                    _this.ele_id = $('#del_dm_id')

                    let name = $('#depart').val();
                    let id = $('#depart_id').val();
                    if (!name) {
                        layer.msg('请选择责任部门')
                        return
                    }

                    _this.ele.val(name)
                    _this.ele_id.val(id)
                    // _this.open()
                })
            }
        }
        /* 选择人员 */
        function Select_People() {
            this.user_url = '${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}&T=addpagesql&page=1&limit=10';

            this.init = function() {
                // 检查人
                let _this = this;
                this.initTree({
                    inst_el: '#inspeople',
                    inst_name: 'inspeople',
                    inst_centent: "<div id='a'><table id='transfer' lay-filter='transferTable'></table></div>",
                    table_ele: 'transfer',
                    table_filter: 'transferTable',
                    check: true
                });

                // 陪检人
                this.initTree({
                    inst_el: '#accompany',
                    inst_name: 'accompany',
                    inst_centent: "<div id='b'><table id='transfer1' lay-filter='transferTable1'></table></div>",
                    table_ele: 'transfer1',
                    table_filter: 'transferTable1',
                    check: false
                });
                // 同行人
                this.initTree({
                    inst_el: '#peerpeople',
                    inst_name: 'peerpeople',
                    inst_centent: "<div id='c'><table id='transfer2' lay-filter='transferTable2'></table></div>",
                    table_ele: 'transfer2',
                    table_filter: 'transferTable2',
                    check: false
                });

            };
            this.initTree = function(option = {}) {
                let { inst_el, inst_name, inst_centent, table_ele, table_filter, check } = option;
                let _this = this;
                if (!inst_el) {
                    layer.msg('页面出错！请重新加载');
                    parent.layer.closeAll();
                    return
                }
                let ins = xmSelect.render({
                    el: inst_el,
                    name: inst_name,
                    content: inst_centent,
                    height: '500px',
                    autoRow: true,
                    clickClose: true,
                    radio: true,
                    data: [], //list,
                    prop: { name: 'title' },
                    on: function(data) {
                        ins.closed();
                    }
                })
                if (check) {
                    /****************行走路线*******************/
                    loadLine.render({
                        ele: '#yh_route',
                        url: "/api/RYDW-GetPersonLocaionData",
                        where: "keyword",
                        cententName: 'yh_lib_content',
                        local: true,
                        wherereq: function() {
                            let insValue = ins.getValue();
                            let usersId = insValue[0] ? insValue[0].value.split('~')[1] : ''
                            return {
                                userId: usersId
                            }
                        },
                    })
                }
                if (!ins) return;
                this.tree_transfer_table({ table_ele, table_filter, ins, check });
            }
            this.tree_transfer_table = function(option = {}) {
                let { table_ele, table_filter, ins, check } = option;

                let _this = this;

                table.render({
                    url: '${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}&T=addpagesql',
                    elem: `#${table_ele}`,
                    height: 390, //容器高度
                    width: 430,
                    size: 'sm',
                    even: true,
                    skin: 'row',
                    toolbar: '#toolbarDemo', //开启头部工具栏，并为其绑定左侧模板
                    defaultToolbar: [],
                    id: table_filter,
                    cols: [
                        [, { field: 'value', title: 'ID', hide: true },
                            {
                                field: 'title',
                                title: '用户名',
                                templet: function(d) {
                                    if (d.title) {
                                        return d.title
                                    } else {
                                        return d.users_name
                                    }
                                }
                            },
                            { field: 'department_name', title: '部门', },
                            { field: 'department_id', title: '部门id', hide: true },
                            { field: 'level', title: '级别', width: 120, hide: true }
                        ]
                    ],
                    page: true,

                });
                table.on(`toolbar(${table_filter})`, function(obj) {
                    var checkStatus = table.checkStatus(obj.config.id);
                    switch (obj.event) {
                        case 'refresh':
                            table.reload(`${table_filter}`, {
                                where: {
                                    keyword: ''
                                },
                                page: {
                                    curr: 1
                                }
                            }, true)
                            break;
                        case 'search':
                            let old = $(`#${table_ele} + div input[name="keyword"]:eq(0)`).val();

                            table.reload(`${table_filter}`, {
                                where: { keyword: old },
                                page: { curr: 1 },
                            }, true)
                            $(`#${table_ele}+ div input[name="keyword"]:eq(0)`).val(old)
                            break;
                    }
                })
                table.on(`row(${table_filter})`, function(obj) {
                    if (check) {
                        ins.update({ data: [] })
                    }
                    var values = ins.getValue();
                    var item = obj.data;

                    var has = values.find(function(i) {
                        return i.value === item.value
                    })
                    if (check) {
                        item.value = item.title + '~' + item.value.split('~')[1]
                    }

                    if (has) {
                        ins.delete([item]);
                    } else {
                        ins.append([item]);
                    }

                });
            }
        }
        /* 日期 */
        function Select_Date() {

            this.insSaveTime = '$!id' ? moment(backData.inspectiondate).utcOffset(480).format('YYYY-MM-DD') : moment().utcOffset(480).format('YYYY-MM-DD');
            this.init = function() {
                let _this = this;

                /* 检查日期 */
                laydate.render({
                    elem: '#formAdvDateSel1',
                    range: false,
                    trigger: 'click',
                    value: _this.insSaveTime,
                    min: -2, //3天前
                    max: 0, //1天后
                    done: function(value, date) {
                        $('#date1').val(value)
                        let stamp = moment(value) - moment($('#date1').val())
                        let difference = moment.duration(Math.abs(stamp)).days()
                        // 要求完成时间后的单选框
                        form.val('formAdvForm', { like1: difference });
                        _this.update();
                    }
                });

                this.res_time();
            };

            this.res_time = function(ele = "#date_time", f = 'formAdvForm_0', name = "like_0", radio_filter = "radio") {
                let yaoquiTime = '$!id' ? moment(backData.yh_requesttime).utcOffset(480).format('YYYY-MM-DD') : moment().utcOffset(480).format('YYYY-MM-DD');
                // 要求完成日期
                // push 进数组 ，updata 调用
                let _lay_d = laydate.render({
                    elem: ele, // '#date_time',
                    range: false,
                    trigger: 'click',
                    value: yaoquiTime,
                    showBottom: false,
                    isInitValue: true, //是否允许填充初始值，默认为 true
                    min: 0,
                    done: function(value, date) {
                        let stamp = moment(value) - moment($('#formAdvDateSel1').val())
                        let difference = moment.duration(Math.abs(stamp)).days()
                        // 要求完成时间后的单选框

                        if (difference > 3) {
                            difference = 4;
                        }
                        let obj = {};
                        obj[name] = difference
                        form.val(f, obj)
                    }
                });
                RES_LAYDATE.push(_lay_d)
                // 要求整改时间
                form.on(`radio(${radio_filter})`, function(data) {
                    // 基于检查时间
                    let inspectTime = new Date($('#formAdvDateSel1').val());
                    let nowDay = moment(inspectTime).add(data.value * 1, 'd').format('YYYY-MM-DD')
                    $(ele).val(nowDay)
                });
            }
            this.update = function update() {
                let min = $('#formAdvDateSel1').val();

                $('input[name="yh_requesttime"]').each(function(index, element) {
                    $(element).val(min)
                    let i = $(element).attr('label_radio')
                    let str = 'like_' + i;
                    let f = 'formAdvForm_' + i
                    let obj = {};
                    obj[str] = 0;
                    form.val(f, obj)
                })
                let arr = RES_LAYDATE;
                for (var i = 0; i < arr.length; i++) {
                    const config = arr[i];
                    config.config.min = {
                        year: moment(min).year(),
                        month: moment(min).utcOffset(480).month(), //关键
                        date: moment(min).utcOffset(480).date(),
                        hours: 0,
                        minutes: 0,
                        seconds: 0
                    };
                }

            }
        }
        /* 隐患种类 */
        function Select_Xmyh_Type() {
            this.dangerType = null;
            this.url = '${cls.getrooturl()}?type=sel&tabid=YH_typee42dae76-066e-4d45-baa9-19193229c76c&mid=028e9fcb-ffd9-49e4-bc78-a7c26a5bf620&job=demo_node_1&tbname=xt_dict&T=隐患种类sql'
            this.init = function() {
                this.xmrender();
                this.request();
            };
            this.xmrender = function() {
                // 隐患种类
                this.dangerType = xmSelect.render({
                    el: '#yh_kind',
                    name: 'yh_kind',
                    layVerify: 'required',
                    layReqText: '请选择隐患种类',
                    layVerType: 'msg',
                    direction: 'up',
                    prop: {
                        name: 'dict_name',
                        value: 'dict_name',
                    },
                    radio: true,
                    clickClose: true,
                    tree: {
                        show: true,
                        strict: false,
                        expandedKeys: [-1],
                    },
                    height: '300px',
                    filterable: true,
                })

            };
            this.request = async function() {
                let _this = this;
                const yhType = await axios({
                    url: _this.url,
                    method: 'post',
                    load: false
                });
                if (yhType.code == 0) {
                    let data = yhType.data;
                    this.setData(data)
                }
            };
            this.setData = function(result) {
                let danger = result; //隐患种类

                let dangerTree = treeTable.pidToChildren(danger, 'ids', 'dict_pid', 'children')
                this.dangerType.update({
                    data: dangerTree
                });
                // 编辑 -- 缓存 
                // let js = data$sjs

                // if (data$sjs) { // 编辑
                //     dangerTyoe.setValue([
                //         js.yh_kind
                //     ])
                // } else { // 缓存数据
                //     let cache = layui.data('yhadd');
                //     if (cache.yh) {
                //         dangerTyoe.setValue([
                //             cache.yh.yh_kind
                //         ])
                //     }
                // }
            }
        }
        /* 文件上传 */
        function Upload() {
            /*** 渲染列表 ***/
            this.list = [];
            // 回显数据
            this.fileShowImg = [] // data$sjs;
            // 是否有文件
            this.isUpload = false;
            this.init = function() {
                this.upload();
            };
            this.upload = function() {
                let _this = this;
                //多文件列表
                var uploadListIns = upload.render({
                    elem: '#testList',
                    elemList: $('#demoList'), //列表元素对象
                    url: '../root/HandlerUpload.ashx?type=3',
                    accept: 'file',
                    multiple: true,
                    auto: false,
                    bindAction: '#testListAction',
                    before: function(obj) {
                        notice.msg('上传中...', { icon: 4, close: true, displayMode: 2 });
                    },
                    choose: function(obj) {
                        _this.isUpload = true; // 是否选择了文件
                        var that = this;
                        var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
                        //读取本地文件
                        obj.preview(function(index, file, result) {
                            var tr = $(['<tr id="upload-' + index + '">', '<td>' + file.name + '</td>', '<td>' + (file.size / 1014).toFixed(1) + 'kb</td>', '<td><div class="layui-progress" lay-filter="progress-demo-' + index + '"><div class="layui-progress-bar" lay-percent=""></div></div></td>', '<td>', '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>', '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>', '</td>', '</tr>'].join(''));

                            //单个重传
                            tr.find('.demo-reload').on('click', function() {
                                obj.upload(index, file);
                            });

                            //删除
                            tr.find('.demo-delete').on('click', function() {
                                delete files[index]; //删除对应的文件
                                tr.remove();
                                uploadListIns.config.elem.next()[0].value = ''; //清空 input file 值，以免删除后出现同名文件不可选
                            });

                            that.elemList.append(tr);
                            element.render('progress'); //渲染新加的进度条组件
                        });
                    },
                    done: function(res, index, upload) { //成功的回调
                        var that = this;
                        if (res.code == 200) { //上传成功
                            var tr = that.elemList.find('tr#upload-' + index),
                                tds = tr.children();
                            tds.eq(3).html(''); //清空操作
                            filePath.push(res.url)
                            delete this.files[index]; //删除文件队列已经上传成功的文件
                            return;
                        }
                        this.error(index, upload);
                    },
                    allDone: function(obj) {
                        //多文件上传完毕后的状态回调
                        notice.destroy();
                        if (obj.successful == obj.total) {
                            ajaxForm();
                        }
                    },
                    error: function(index, upload) { //错误回调
                        var that = this;
                        var tr = that.elemList.find('tr#upload-' + index),
                            tds = tr.children();
                        tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
                    },
                    progress: function(n, elem, e, index) {
                        element.progress('progress-demo-' + index, n + '%'); //执行进度条。n 即为返回的进度百分比
                    }
                });
            }
            this.renderList = async function(dataList) { //renderList
                // 文件列表
                let _this = this
                let file = dataList.filepath.split(',');
                this.list = [];
                file.forEach((url) => {
                    list.push({
                        "name": url.split('_')[1],
                        "isDir": false,
                        "type": url.split('.')[1],
                        url
                    })
                })
                var htmlStr = fileChoose.renderList({
                    data: _this.list,
                    menu: [{
                            name: '预览',
                            event: 'preview'
                        },
                        {
                            name: '下载',
                            event: 'down'
                        }, {
                            name: '<span style="color: red;">删除</span>',
                            event: 'del'
                        }
                    ]
                });
                $('#file-list-group').html(htmlStr);
                // 点击空白隐藏下拉框
                $(document).off('click.fclomp').on('click.fclomp', function(e) {
                    $('.file-choose-oper-menu').removeClass('show');
                });

                // 菜单事件监听
                $(document).off('click.fclomip').on('click.fclomip', '#file-list-group .file-choose-oper-menu-item', function() {
                    var event = $(this).data('event');
                    var dataIndex = $(this).parent().parent().data('index');
                    if (event == 'del') {
                        // 删除
                        layer.confirm('确定要删除此文件吗？', { shade: .1 }, function() {
                            layer.msg('操作成功', { icon: 1 });
                            let backPath = _this.fileShowImg.filepath.split(',')
                            backPath.splice(dataIndex, 1)
                            _this.fileShowImg.filepath = backPath.join(',')
                            filePath.splice(dataIndex, 1)
                            renderList(_this.fileShowImg);
                        });
                    } else if (event == 'preview') {
                        if (_this.list[dataIndex].type == 'mp4') {
                            let src = _this.list[dataIndex].url;
                            layer.open({
                                type: 1,
                                zIndex: layer.zIndex, //重点1
                                title: '视频预览',
                                shadeClose: true,
                                shade: true,
                                maxmin: true, //开启最大化最小化按钮
                                area: ['600px', '600px'],
                                content: $('#ifram').html(),
                                success: function() {
                                    $('#vsource').attr('src', src)
                                }
                            })

                        } else {
                            window.open(_this.list[dataIndex].url);
                        }

                    } else {
                        _this.downloadImg(_this.list[dataIndex].url)
                    }
                });
            };
            /**
             * @description: 下载图片
             * @param {*} url
             * @return {*}
             */
            this.downloadImg = function(url) {
                var img = document.getElementById('testImg'); // 获取要下载的图片
                var a = document.createElement('a'); // 创建一个a节点插入的document
                var event = new MouseEvent('click') // 模拟鼠标click点击事件
                a.download = '下载' // 设置a节点的download属性值
                a.href = url; // 将图片的src赋值给a节点的href
                a.dispatchEvent(event) // 触发鼠标点击事件
            }
        }
        /*  隐患内容 */
        function Yh_Element() {
            // form 表单
            // this.form_array = ['formAdvForm_3'];
            Main.call(this);
            this.ele = $('#yhContent > form').eq(0);
            this.init = function() {
                let _this = this;
                $('#add_yh_content').on('click', function() {
                    _this.render();
                    return false
                })
                /* 事件委托  ---删除 */
                $('#yhContent').on('click', '.del-row', function(e) {
                    let target = e.target
                    const row = $(this).parents('.layui-active-row').eq(0);
                    let i = $(this).attr('index');
                    // console.log(i)
                    _this.form.splice(i, 1)
                    main._set('form', _this.form)
                    row.remove();
                })
                /* 事件委托  ---复制  */
                $('#yhContent').on('click', '.copy-row', function(e) {
                    const row = $(this).parents('.layui-active-row').eq(0);
                    let ele_clone = row.clone()

                    $('#yhContent').append(ele_clone)

                    _this.input_filter(ele_clone, false)

                })
                /* 初始-隐患内容搜索 */
                loadsearch.render({
                    ele: '#yh_content',
                    url: "${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=demo_node_1&tbname=${tbname}&T=yhlibsql",
                    where: "keyword",
                    cententName: 'yh_lib_content'
                })
            };
            this.render = function() {
                /* 克隆 */
                const clone_ele = this.ele.clone();

                $('#yhContent').append(clone_ele);
                // 修改 
                this.input_filter(clone_ele)

            };
            this.input_filter = function(ele, clear = true) {
                let indexs = $(ele).index();
                if (indexs < 0) return;
                let str = 'formAdvForm_' + indexs
                $(ele).attr('id', str)
                $(ele).attr('lay-filter', str)
                // 保存
                this.form.push(str)
                // main.form = this.form
                main._set('form', this.form)
                /*  单选问题 */
                let input = $(ele).find('input')
                let textareas = $(ele).find('textareas')

                input.each(function(index, element) {
                    let old = $(element).attr('name_data');
                    // 单选问题
                    if ($(element).attr('type') == 'radio') {
                        $(element).attr('name', `${old}_${indexs}`)

                        $(element).attr('lay-filter', `radio_${indexs}`)

                    }
                    $(element).attr('label_radio', `${indexs}`)
                })
                textareas.each(function(index, element) {
                    if (clear) {
                        $(element).val('')
                    }
                })
                form.render();
                /* 按钮 */
                let btn = $(ele).find('.config_btn')
                $(btn).removeClass('layui-hide')
                $(ele).find('.del-row').attr('index', indexs)
                /* 内容 */
                let center = $(ele).find('.yh_content')


                center.each(function(index, element) {

                    let old = $(element).attr('id');
                    let ID = old + '_' + indexs
                    $(element).attr('id', `${old}_${indexs}`);
                    /***************隐患内容搜索***************/
                    loadsearch.render({
                        ele: `#${ID}`,
                        url: "${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=demo_node_1&tbname=${tbname}&T=yhlibsql",
                        where: "keyword",
                        cententName: 'yh_lib_content'
                    })
                })

                /* 时间 */
                let time = $(ele).find('input[name="yh_requesttime"]');
                // 改变id
                $(time).eq(0).attr('id', `yh_requesttime_${indexs}`);
                // 多个时间的话，无法刷新最小 选择时间  已解决
                const date_time = new Select_Date()
                date_time.res_time(`#yh_requesttime_${indexs}`, 'formAdvForm_' + indexs, "like_" + indexs, "radio_" + indexs)


            }
        }
        /* 保存 */
        function Submit() {
            this.stateType = 0;
            this.other_obj_params = {}; // 其他完整参数
            Main.call(this);

            this.init = function() {

                this.event();
            };

            this.event = function() {
                let _this = this
                /* 提交并下达 */
                form.on('submit(formAdvSubmit)', function(data) {
                    _this.stateType = 1;
                    /* 验证 */
                    if (_this.verifi()) {
                        _this._getParams();
                        _this.eachAxios();
                    }

                    return false
                })
                /* 保存 */
                form.on('submit(formAdvSubmitSave)', function(data) {
                    _this.stateType = 0
                    /* 验证 */
                    if (_this.verifi()) {
                        _this._getParams();
                        _this.eachAxios();

                    }
                    return false
                })
                /* 编辑时保存 */
                form.on('submit(detailFormAdvSubmitSave)', function(data) {
                    _this.stateType = 0;
                    /* 验证 */
                    if (_this.verifi()) {
                        _this._getParams();
                        _this.eachAxios();

                    }

                    return false
                })
            };
            /* 特殊情况判断 */
            this.verifi = function() {
                // 带班领导
                if (form.val("formAdvForm_leader").leader == 'on') {
                    if (!form.val("formAdvForm_leader").yh_route) {
                        notice.msg('您是带班领导，请选择行走路线', { icon: 3 })
                        return false;
                    }
                    return true;
                };
                if (form.val("formAdvForm_basis").inspeople == '') {
                    notice.msg('请选择检查人', { icon: 3 })
                    return false
                }
                return true;

            };
            /* 获取数据 */
            this._getParams = function() {
                // 隐患状态
                let stateType = this.stateType;
                // 默认form
                let defaultform = main.defaultform;

                let obj = {
                    level: '$cls.setck("level")', // 隐患等级
                    /* 废弃 */
                    yh_circuit: '{}', //废弃   
                    yh_terms: '', //废弃
                    personalfine: 0, // 废弃但不能删除，三违罚款统计里调用
                    fine: 0, //废弃但不能删除，三违罚款统计里调用 
                    /* 废弃 */
                };
                for (var i = 0; i < defaultform.length; i++) {
                    const element = defaultform[i];
                    let formdata = form.val(element);
                    obj = Object.assign(obj, formdata)
                }
                // 检查部门
                let insBumenName = obj.inspeople.split('~')[2] ? obj.inspeople.split('~')[2] : '$cls.setck("department_name")';
                let insBumenId = obj.inspeople.split('~')[3] ? obj.inspeople.split('~')[3] : '$cls.setck("department_id")';
                let origin = obj + '~' + insBumenId;
                obj.yh_origin = origin;
                // 责任追究
                if (!obj.accountability) {
                    obj.accountability = '0';
                } //12
                this.other_obj_params = obj;

                // 完整值
                let params = []
                // 隐患内容
                let array = main.form;
                for (var i = 0; i < array.length; i++) {
                    const element = array[i]
                    let formdata = form.val(element);
                    if (i != 0) {
                        let obj_key = `yh_level_${i}`
                        formdata.yh_level = formdata[obj_key]
                        delete formdata[obj_key];
                    };
                    let like = `like_${i}`

                    let nowxh = $(`input[name=${like}]:checked`).attr('title');
                    if (nowxh == '当班整改' && stateType != 0) {
                        stateType = 8 //隐患状态 --当班整改 下达直接销号 8 保存不走
                    }

                    /* 隐患状态 */
                    formdata.yh_state = stateType;
                    params.push(formdata)
                }
                /* Array */
                this.params = params;
            }
            this.eachAxios = async function() {
                if (!this.params) return;
                // 改变 this 
                let _this = this;
                // 获取 其他 name 值
                let params_obj = this.other_obj_params;
                /* 深拷贝  */
                let copy = this.params;;
                let array = JSON.parse(JSON.stringify(copy));
                /* 加载动画 */
                const index = layer.load();
                for (var i = 0; i < array.length; i++) {
                    const element = array[i];
                    element.yh_content.replace(/[\r\n]/g, ' ');

                    let newPromise = await _this.genNewYhCode(element)
                    console.log(newPromise)
                }
                layer.close(index)

            };
            /* 获取code */
            this.genNewYhCode = async function(content) {
                let _this = this;
                let res = null;
                let params = this.other_obj_params;

                let inspectiondate = params.inspectiondate || '';
                try {
                    res = await axios({
                        url: '/api/GenNewYinHuanCode',
                        method: 'post',
                        data: Qs.stringify({
                            date: inspectiondate
                        }),
                        load: true
                    })
                } catch (e) {
                    res = { code: 1 };
                    return false
                }
                if (res && res.code == 0) {
                    let codeParam = JSON.parse(JSON.stringify(params));
                    delete codeParam.yh_code;
                    codeParam.yh_code = res.data;

                    await _this.getAxios(codeParam)
                }
            }
            /* 发送请求 */
            this.getAxios = async function(close = false, params) {
                let obj = {
                    operating_json: JSON.stringify(params), // 保存历史记录
                    operating_type: '隐患下达', //操作类型 -- 后台已判断
                    filepath: filePath.join(','), // 文件路径
                    id: close ? id : guid(), // 保存时不会关闭，所以刷新id
                }
                if ("$!{id}") { // 编辑
                    const res = await axios({
                        method: 'post',
                        url: '$cls.getrooturl()?type=ajaxaddup&mid=$!{mid}&tabid=$!{tabid}&job=${job}&tbname=${tbname}&T=updateselsql',
                        data: Qs.stringify(params),
                        load: false
                    }).catch(e => {
                        layer.msg('编辑修改失败！', { icon: 5 })
                    })
                } else {
                    // 请求开始--新建
                    delete params.id;
                    params.id = guid(); // 修改id
                    const res = await axios({
                        method: 'post',
                        url: '$cls.getrooturl()?type=ajaxaddup&mid=$!{mid}&tabid=$!{tabid}&job=${job}&tbname=${tbname}&T=circuit',
                        data: Qs.stringify(params),
                        load: false,
                    }).catch(e => {
                        layer.msg('新增隐患失败')
                    })
                    // if (res) {
                    //     notice.msg('添加成功', { icon: 1, displayMode: 0 });
                    // }

                    // if (close) {
                    //     parent.layer.closeAll();
                    // } else {
                    //     // 重置隐患内容
                    //     $('textareas[name=yh_content]').each(function() {
                    //         this.value = ''
                    //     })
                    //     $('textareas[name=yh_content]').each(function() {
                    //         this.value = ''
                    //     })

                    //     document.getElementById('yh_rectify').value = ''
                    //     // 缓存隐患数据
                    //     layui.data('yhadd', {
                    //         key: 'yh',
                    //         value: params
                    //     })
                    // }
                }
            }

        }
        /* 回显 */
        function Show() {

        }
        /*
         * layui 插件部分
         *
         */
        /*  检查地点   */
        loadsearch.render({
            ele: '#address_name',
            idele: '#address_id',
            url: "${cls.getrooturl()}?type=sel&tabid=${tabid}&mid=${mid}&job=${job}&tbname=${tbname}&T=风险点管理SQL",
            where: "keyword",
            wherereq: function() {
                return {
                    ascription: $('#pname').val()
                }
            },
            cententName: 'fxd_names',
            template: `<div></div>`
        })
        /* 生成id */
        function guid() {
            return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
                var r = Math.random() * 16 | 0,
                    v = c == 'x' ? r : (r & 0x3 | 0x8);
                return v.toString(16);
            });
        }
    });
    </script>
</body>

</html>